package view;

import controller.AccountController;
import dto.*;
import view.HelperClasses.BackgroundPanel;
import view.HelperClasses.ContentPane;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import view.WelcomePanels.*;;

/**
 *
 * @author Joachim
 */
public class WelcomeFrame extends JFrame {
    
    private AccountController controller;
    private JPanel cards, backgroundPanel;
    private JPanel loginPanel;

    public WelcomeFrame(AccountController controller) {
        
        this.controller = controller;
        
        this.setSize(420,320);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setUndecorated(true);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Apply a transparent color to the background
        // This is ALL important, without this, it won't work!
        setBackground(new Color(0, 255, 0, 0));

        // This is where we get sneaky, basically where going to 
        // supply our own content pane that does some special painting
        // for us
        setContentPane(new ContentPane());
        getContentPane().setBackground(Color.BLACK);
        setLayout(new BorderLayout());        
        
        // Add our background image pane...    
        backgroundPanel = new BackgroundPanel(this, getClass().getResource("/resources/welcomeFrame-bg.png"));
        backgroundPanel.setBackground(new Color(0, 255, 0, 0)); 
        
        loginPanel = new LoginPanel(new LoginDTO(), controller, this);
        JPanel registerPanel = new RegisterPanel(new RegisterDTO(), controller, this);
        JPanel resetPasswordPanel = new ResetPasswordPanel(new ResetPasswordDTO(), controller, this);
        
        cards = new JPanel(new CardLayout());
        cards.setOpaque(false);
        cards.add(loginPanel, "LOGIN");
        cards.add(registerPanel, "REGISTER");
        cards.add(resetPasswordPanel, "RESETPASSWORD");
        
        backgroundPanel.add(cards);
        showCard("LOGIN");
        
        add(backgroundPanel);
        setVisible(true);
        
        // Taskbar icons
        List<Image> icons = new ArrayList<Image>();
        icons.add(new ImageIcon(getClass().getResource("/resources/logos/logo32x32.png")).getImage());
        icons.add(new ImageIcon(getClass().getResource("/resources/logos/logo64x64.png")).getImage());
        icons.add(new ImageIcon(getClass().getResource("/resources/logos/logo128x128.png")).getImage());
        icons.add(new ImageIcon(getClass().getResource("/resources/logos/logo256x256.png")).getImage());
        icons.add(new ImageIcon(getClass().getResource("/resources/logos/logo512x512.png")).getImage());
        this.setIconImages(icons);
    }
    
    public void showCard(String card) {
        CardLayout cardLayout = (CardLayout) cards.getLayout();
        cardLayout.show(cards, card);
        repaint();
    }
}
